<template>
    <view :style="themeColor">
        <view class="page" >
<!---flex布局flex布局开始-->
 <view class="flex flex-direction align-stretch benben-flex-layout" :style="{'padding-top':`20vh`}"   >
            <view   class='flex align-center justify-center'      >
        <image class='wxBandPhone_fd0_0_c0'  mode="aspectFit"  :src='STATIC_URL+"222.png"'></image>
</view>
    <view   class='flex flex-direction align-stretch wxBandPhone_fd0_1'      >
        <text class='wxBandPhone_fd0_1_c0'  >申请获取以下权限</text>
<text class='wxBandPhone_fd0_1_c1'  >获取你的手机号码信息</text>
<button class='wxBandPhone_fd0_1_c2'  @getphonenumber="getPhoneNumberFunc($event)"  open-type="getPhoneNumber" >绑定手机号</button>
</view>
</view>
        
<!---flex布局flex布局结束-->
    
    
        </view>
    </view>
</template>
<script>
    import {validate} from '@/common/utils/validate.js'
    
    export default {
        components:{},
        
        
        data(){
			return {"code":"","aaa":{"userinfo":{"user_token":"","id":"","avatar":"","real_name":"","nickname":"","email":"","gender":"","mobile":"","birthday":"","client_id":"","phone":""}}};
		},
		computed:{
            themeColor() {
              return this.$store.getters.themeColor
            },
            
		},
		watch:{},
		onLoad(options){
            
		},
        onUnload() {
                
        },
		onReady(){
            
		},
		onShow(){
            
		},
		onHide(){
            
		},
		onResize(){
            
		},
		onPullDownRefresh(){
            
		},
		onReachBottom(e){
            
		},
		onPageScroll(e){
            
		},
		methods:{
                            //获取手机号
                 getPhoneNumberFunc(e){
                        // 用户取消授权,返回上一页
      // 用户同意授权,调用登录方法
      if (e.detail.errMsg.indexOf('user deny') !== -1) {
        uni.navigateBack();
      } else {
        this.bindMoblileFunc(e.detail.encryptedData, e.detail.iv,e.detail.code);
      }
                },
                //绑定手机号
                async bindMoblileFunc(encrypteddata,iv,code){
                        uni.showLoading({
    title: this.i18n['绑定中...']
});
// 获取用户授权信息
uni.login({
    success: async res => {
        var oldInfo = uni.getStorageSync('Wxinfo_tmp')
        var infoStr = {
            openid: oldInfo.openid,
            code,
            iv,
            encrypteddata
        }
        /* 用户信息发给后台 */
        let resData = await this.$api.dbPost(global.apiUrls.post5d7757d28d076, {
            extend_info: JSON.stringify(infoStr),
            account_type: "mobile",
            third_type: 'wx_miniapp'
        });
        var r = resData.data
        uni.hideLoading();
        if (r.code == 1) {
            uni.removeStorageSync('Wxinfo_tmp');
            // 保存用户信息到 store 中
            this.$store.commit('saveToken', r.data.userinfo.user_token)
            this.$store.commit('updateUserInfo', r.data.userinfo);
            uni.navigateBack();
        } else {
            this.$message.info(res.msg);
        }
    }
});
                }
		}
    };
</script> 
<style lang="scss" scoped>
           .page{
            width: 100vw;
            overflow-x: hidden;
            min-height: calc(100vh - var(--window-bottom));
            background:var(--benbenbgColor1);background-size: 100% auto;
        }
    .wxBandPhone_fd0_1_c2{
        background:var(--benbenbgColor7);border-radius:100rpx;line-height:88rpx;font-size:32rpx;color:#fff;margin:88rpx 0rpx 0rpx 0rpx;
    }
    .wxBandPhone_fd0_1_c1{
        font-size:28rpx;font-weight:400;color:var(--benbenFontColor2);
    }
    .wxBandPhone_fd0_1_c0{
        margin:0rpx 0rpx 24rpx 0rpx;font-size:28rpx;font-weight:600;color:var(--benbenFontColor0);
    }
    .wxBandPhone_fd0_1{
        padding:156rpx 56rpx 0rpx 56rpx;
    }
    .wxBandPhone_fd0_0_c0{
        width:180rpx;height:180rpx;border-radius:0rpx 0rpx 0rpx 0rpx;
    }
</style>